import cv2
from matplotlib import pyplot as plt
# 读取并显示图像
im = cv2.imread("test.jpg", 0)
cv2.imshow("orig", im)

# 绘制灰度图像的直方图
plt.hist(im.ravel(), 256, [0,256])
plt.show()

# 调用opencv的直方图均衡化API
im_equl = cv2.equalizeHist(im)
cv2.imshow("equal", im_equl)

# 显示原始图像的直方图
plt.subplot(2, 1, 1)
plt.hist(im.ravel(), 256, [0,256], label="orig")
plt.legend()

# 显示均衡化图像的直方图
plt.subplot(2, 1, 2)
plt.hist(im_equl.ravel(), 256, [0,256], label="equalize")
plt.legend()
plt.show()

cv2.waitKey()

# 调用opencv的中值模糊API
im_medianblur = cv2.medianBlur(im, 5)

cv2.imshow("median_blur",im_medianblur )

cv2.waitKey()
